/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetocompiladores;

import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import org.jhotdraw.draw.AttributeKeys;
import org.jhotdraw.draw.DiamondFigure;
import org.jhotdraw.draw.GraphicalCompositeFigure;
import org.jhotdraw.draw.TextFigure;

/**
 *
 * @author gtavcs
 */
public class LabeledDiamondFigure extends GraphicalCompositeFigure {

    String text;

    public LabeledDiamondFigure(String text, 
                                Point2D.Double posicao) {
        setPresentationFigure(new DiamondFigure());
        this.text = text;
        TextFigure label = new TextFigure(text);
        label.set(AttributeKeys.FONT_BOLD, true);
        
        double offsetX = posicao.x + label.getBounds().width + 40;
        double offsetY = posicao.y + label.getBounds().height + 40;
        setBounds(posicao, new Point2D.Double(offsetX, offsetY));
        
        double centerFigureX = this.getBounds().getCenterX();
        double centerLabelX = label.getBounds().getCenterX();

        label.transform(new AffineTransform(0, 0, 0, 0, centerFigureX - centerLabelX, this.getBounds().getCenterY() - label.getBounds().getCenterY()));
        
        add(label);
    }

    public String getText() {
        return text;
    }

}
